#!/usr/bin/env python
# -*- coding: utf-8 -*-
# pip install -r requirements.txt


with open(r'guxiang.txt', 'r', encoding='utf-8') as f:
    lines = f.readlines()
    for line in lines:
        print(line[:-1])

n = 'abcdefg椒盐蘑菇'  # unicode
g = n.encode('gbk')  # gbk
u = n.encode('utf-8')  # utf-8
g2 = n.encode('gb2312')  # gb2312
g2u = g.decode("gbk").encode("utf-8")  # gbk转成utf-8


def info_str(s):
    print(f'{s}, {type(s)}')


info_str(n)
info_str(g)
info_str(u)
info_str(g2)
info_str(g2u)

import chardet

cs = chardet.detect(g)
print(cs)


def detect_encoding(s):
    cs = chardet.detect(s)
    print(cs)


detect_encoding(g)
detect_encoding(u)
detect_encoding(g2)
detect_encoding(g2u)

import requests

res = requests.get('https://www.fudan.edu.cn')
cs = chardet.detect(res.content)
print()
print(cs)
